<template>
  <div>
    <ContentTitle :info="ctInfo" />

    <!-- 月份选择 -->
    <el-row class="flex aic bg-fff mt-5 pl-15 pt-10 pb-15">
      <el-col :span="2">月份选择</el-col>
      <el-date-picker
        @change="changeDate"
        v-model="date"
        type="month"
        placeholder="选择月"
      >
      </el-date-picker>

      <download-excel
        :data="list"
        :fields="tableTitle"
        type="xlsx"
        worksheet="My Worksheet"
        name="使用记录.xlsx"
      >
        <el-button class="ml-10" type="primary">导出数据 </el-button>
      </download-excel>
    </el-row>

    <el-table stripe border :data="list" style="width: 100%">
      <el-table-column
        align="center"
        :formatter="formatTime"
        prop="cTime"
        label="创建时间"
      >
      </el-table-column>
      <el-table-column align="center" prop="amount" label="金额">
      </el-table-column>
      <el-table-column align="center" prop="desc" label="描述">
      </el-table-column>

       <el-table-column label="操作">
      <template slot-scope="scope">
        <el-button
          size="mini"
          @click="handleEdit(scope.$index, scope.row)">编辑</el-button>
        <el-button
          size="mini"
          type="danger"
          @click="handleDelete(scope.$index, scope.row)">删除</el-button>
      </template>
    </el-table-column>
    </el-table>

    <div class="flex jc-c pt-10 pb-20 bg-fff">
      <el-pagination
        @current-change="changePage"
        background
        :page-size="pageSize"
        :current-page="currPage"
        layout="prev, pager, next"
        :total="total"
      >
      </el-pagination>
    </div>
  </div>
</template> 
<script>
import * as api from "../../api/index";
export default {
  data() {
    return {
      date: null, // 日期
      currPage: 1,
      pageSize: 10,
      total: 0,
      // 表头
      tableTitle: {
        编号: "id",
        类型: "type",
        金额: "amount",
        备注: "desc",
      },
      list: [
        // {
        //   id: "990000199403025342",
        //   type: "usege",
        //   desc: "眼较单九米术部示。",
        //   amount: -200,
        //   cTime: 1627701813629,
        // },
      ],
      ctInfo: {
        type: "计费",
        text: "使用记录",
        msg: "展示当前账户的消息额度的所有使用记录。",
      },
    };
  },

  // 监听日期的变化
  watch: {
    date(value) {
      this.currPage = 1;
      this.getList();
    },
  },

  created() {
    this.getList();
  },

  methods: {
    handleEdit(index,row) {},
    handleDelete(index,row) {
      
    },
    getList() {
      let str = "";
      if (!!this.date) {
        let date = new Date(this.date);
        let Y = date.getFullYear();
        let M = date.getMonth() + 1;
        M = M<10?'0'+M:M;
        str = `${Y}-${M}`
      }

      let data = {
        date: str,
        currPage: this.currPage,
        pageSize: this.pageSize,
      };
      api.$feeUsageList(data).then((res) => {
        this.list = res.data;
        this.total = res.total;
      });
    },

    changePage(page) {
      this.currPage = page;
      this.getList();
    },

    // 切换日期
    changeDate() {
      // this.getList();
    },
  },
};
</script>